package com.yibo.user.config;

import org.springframework.boot.web.server.ConfigurableWebServerFactory;
import org.springframework.boot.web.server.ErrorPage;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpStatus;

import static com.yibo.support.constant.ApiUrlConstant.PUBLIC_URL;

@Configuration
public class BeanConfig {

    @Bean
    public WebServerFactoryCustomizer<ConfigurableWebServerFactory> webServerFactoryCustomizer(){
        //函数式接口，可以用lambda简写
        return (factory -> {
            //定义一个错误页面  指定错误状态为404 找不到资源的错误，指定路径，会自动跳转到/base/404 mapping下
            ErrorPage errorPage = new ErrorPage(HttpStatus.NOT_FOUND,PUBLIC_URL+"/base/404");
            factory.addErrorPages(errorPage);
        });
    }

}
